package com.ivsign.lib_idcardidentification;


import android.os.Handler;
import android.os.Message;
import android.util.Log;

import static android.content.ContentValues.TAG;

/**
 * @description :
 * @autHor :  Jason
 * @date : 2018/8/18 14:26
 */

public class MainHandler extends Handler {

    private IReadListener iReadListener;
    private volatile boolean readingflag;
    private int times=0;

    public MainHandler(IReadListener iReadListener) {
        this.iReadListener = iReadListener;
    }

    public MainHandler(IReadListener iReadListener, boolean flag) {
        this.iReadListener = iReadListener;

        this.readingflag = flag;

    }

    public boolean isReadingflag() {
        return readingflag;
    }

    public void setReadingflag(boolean readingflag) {
        this.readingflag = readingflag;
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case 00:
                break;
            case 01:
//                    byte[] info = (byte[]) msg.obj;
//                    String PersionID = initdata(msg.arg1, info);
//                    i++;
//                    if (debug) Log.e(LOGTAG, "i=====================" + i);
//                    _txtRead.append(PersionID);
                break;

            case 02:
                ProgressResult result = (ProgressResult) msg.obj;
                if (iReadListener != null) {
                    iReadListener.onRead(result);
                }
                // pb.setProgress(result.getProgress());
                break;
            case 03:
                times=1;
                byte[] recData = (byte[]) msg.obj;


                if (iReadListener != null) {
                    iReadListener.onSuccess(DecryptIDCardUtils.ReadCard(recData));
                }


                break;
            case 04:
                readingflag = false;
                times++;

                if (iReadListener != null) {
                    iReadListener.OnFailed(times);
                }

                Log.e(TAG, "dispatchMessage: " + 04);

                break;
            case 44:
//                readingflag = false;
//                if (as != null) {
//
//                } else {
//                    mHandler.removeMessages(44);
//                }
                break;
            case 06:
                break;
            case 10:
                // mHandler.obtainMessage(4).sendToTarget();
                //  Toast.makeText(getApplicationContext(), "请检查网络",
                //Toast.LENGTH_LONG).show();
                break;
            case 11:
                // Toast.makeText(getApplicationContext(), "请检查蓝牙连接", Toast.LENGTH_LONG).show();
                break;
            case 12:
//                image.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.faceid));
//                pb.setProgress(0);
                break;

            default:
                break;
        }
    }

    // 循环发送指令02000250005003线程
    int sleep_times = 3;


}
